<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>积分兑换</title>
    <script>
        $(function () {
            $(".chose").toggle(
                function () {
                    $(this).attr("src","assets/img/1234.png")
                },
                function () {
                    $(this).attr("src","assets/img/123.png")
                }
            )
            sessionStorage.removeItem('exchange_url');
        })
    </script>
    <style>
        .num{border-bottom: 1px solid #F5F5F5;overflow: hidden;padding: 2% 0;}
        .num span{display: block;float: left;margin-left: 5%;}
        .num ul{margin-right: 5%;float: right;overflow: hidden;border: 1px solid #B3B3B3;border-radius: 4px;width:30%;}
        .num ul li{float: left;font-size: 14px;line-height:24px;width:32%;text-align: center;}
        .num ul li:nth-of-type(2){border-left: 1px solid #B3B3B3;border-right: 1px solid #B3B3B3;}
    </style>
</head>
<body>
<div class="wrap-dh">
    <div class="header">
        <p>兑换商品</p>
        <img src="__STATIC__/img/back.png" class="back" onclick=window.location.href="{:url('mobile/user_info/integral_index')}">
    </div>
    <div class="center">
        <div class="address">
            {if condition="$address"}
            <span>收货人</span>
            <p><font id="address_name">{$address.name}</font>   <font id="address_phone"> {$address.phone}</font><span><a href="javascript:to_chos();"><img src="__STATIC__/img_user/next2.png"></a></span></p>
            <p> <font id="address_info"> {$address.area_info}</font> <br/> <font id="address"> {$address.address} </font> </p>
            {else/}
            <a href="javascript:to_chos_add();">
                <p style="text-align: center;color: #0B0909;">去选择收货地址</p>
            </a>
            {/if}
        </div>
    </div>
    <div class="main">
        <div class="content">
            <div class="left">
                <img src="/{$data.picUrl}">
            </div>
            <div class="right">
                <div class="title">
                    <p>{$data.title}</p>
                </div>
                <div class="num">{:intval($data.price)}积分</div>
            </div>
        </div>
    </div>
    <div class="footer">
        <p>积分总额：<span>{$total}</span></p>
        <div>消费积分：<span style="color: red;" id="total" >{:intval($data.price)} </span>  <p class="submit" onclick="to_exchange()">   兑换   </p></div>

    </div>

</div>
<script src="__STATIC__/js/layer_mobile/layer.js"></script>
<script>
    //去添加积分兑换地址
    function to_chos_add(){
        sessionStorage.setItem('exchange_url',"{:url('mobile/user_info/integral_exchange')}?goods_id={:input('goods_id')}");
        window.location.href = "{:url('mobile/user_info/create_address')}";
    }
    //去选择积分兑换地址
    function to_chos(){
        sessionStorage.setItem('exchange_url',"{:url('mobile/user_info/integral_exchange')}?goods_id={:input('goods_id')}");
        window.location.href = "{:url('mobile/user_info/address_manage')}";
    }

    //改变消费积分
    function change_text(){
        if ($('#num').val() != ''){
            $('#total').text(parseInt($('#num').val())*parseInt('{:intval($data.price)}'));
        }
    }
    //提交
    function to_exchange(){

        $.ajax({
            url :"{:url('mobile/user_info/exchange_act')}",
            data:{
                'name' : $('#address_name').text(),
                'phone' : $('#address_phone').text(),
                'area_info' : $('#address_info').text(),
                'address' : $('#address').text(),
                'goods_id' : '{$data.id}',
                'title' : '{$data.title}',
                'number' : 1,
                'picUrl' : '{$data.picUrl}',
            },
            type:'post',
            dataType :'json',
            success : function (data) {
                layer.open({content:data.message,skin:'msg',time:2});
                if (data.code == 200){
                    setTimeout(function () {
                        window.location.href = "{:url('mobile/user_info/integral_index')}"
                    },2000)
                }

            },
            error: function () {
                layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
            }
        })
    }
</script>
</body>
</html>